﻿@using Ext.Net;
@using Ext.Net.MVC;
@{ var X = Html.X(); }

@Scripts.Render("~/Scripts/ContentJs")

@X.ResourceManager().Theme(Theme.Default)

@(X.Viewport()
          .Layout(LayoutType.Fit)
          .Items(
              X.Panel()
                  .Layout(LayoutType.Border)
                  .Border(false)
                  .Items(
                      X.Panel().Border(false)
                          .Region(Region.North)
                          .Layout(LayoutType.Fit)
                          .TopBar(X.Toolbar()
                              .Layout(LayoutType.Fit)
                              .Items(
                                  X.FormPanel()
                                      .BodyStyle("background-color:transparent")
                                      .Border(false)
                                      .ID("SearchFunction")
                                      .Layout(LayoutType.Table)
                                      .LayoutConfig(new TableLayoutConfig { Columns = 4 })
                                      .Items(
                                            X.TextField().FieldLabel("系统功能").LabelAlign(LabelAlign.Right).LabelWidth(80).ID("REMARK").Name("REMARK")
                                      )
                                      .Buttons(
                                          X.Button().Text("查询").OnClientClick("FunctionSearch").Icon(Icon.ApplicationGo),
                                          X.Button().Text("重置").OnClientClick("#{SearchFunction}.getForm().reset();").Icon(Icon.TextfieldDelete)
                                      ),
                                          X.Hidden().ID("searchCondition").Value("")
                              )
                          ),

                      X.GridPanel()
                          .Layout(LayoutType.Fit)
                          .Region(Region.Center)
                          .Border(false)

                          .ID("FunctionGrid")
                          .TopBar(X.Toolbar()
                              .Layout(LayoutType.VBox)
                              .LayoutConfig(new VBoxLayoutConfig { Align = VBoxAlign.Stretch })
                              .Items(

                                  X.Panel()

                                      .BodyStyle("background-color:transparent")
                                      .Layout(LayoutType.HBox)
                                      .LayoutConfig(new HBoxLayoutConfig { Align = HBoxAlign.Middle, Pack = BoxPack.Start })
                                      .Border(false)
                                      .BodyPadding(5)
                                      .Items(
                                              X.Button().Text("添加系统功能").Icon(Icon.Add).MarginSpec("0 10 0 0").OnClientClick("ShowAddFunction"),

                                          X.Button().Text("修改系统功能").Icon(Icon.ApplicationEdit).MarginSpec("0 10 0 0").OnClientClick("ShowModFunction"),
                                              X.Button().Text("删除系统功能").Icon(Icon.Delete).MarginSpec("0 10 0 0").OnClientClick("DelFunction")

                                      )


                                      )


                          )
                          .ColumnModel(
                              X.RowNumbererColumn(),
                              X.Column().Text("ID").DataIndex("ID"),
                              X.Column().Text("系统功能代码").DataIndex("FUNCID"),
                              X.Column().Text("系统功能说明").DataIndex("REMARK"),
                              X.Column().Text("操作")
                          )
                          .Store(
                              X.Store().Model(X.Model().Fields(
                                  new ModelField("rn", ModelFieldType.Int),
                                      new ModelField("ID", ModelFieldType.Int),
                                      new ModelField("TITLE", ModelFieldType.String),
                                      new ModelField("FUNCID", ModelFieldType.String),
                                      new ModelField("REMARK", ModelFieldType.String))
                                  )
                                  .RemoteFilter(true)
                                  .PageSize(20)
                                      .Parameters(o => o.Add(X.StoreParameter().Name("searchCondition").Value("JSON.stringify(serializeJson(\"SearchFunction\"))").Mode(ParameterMode.Raw)))
                                  .Proxy(X.AjaxProxy()
                                      .Url(Url.Action("LoadFunction"))
                                      .ActionMethods(o => { o.Read = HttpMethod.POST; })
                                      .Reader(X.JsonReader().RootProperty("data"))
                                      )
                                  )
                                  .SelectionModel(X.CheckboxSelectionModel().Mode(SelectionMode.Single))
                                  .EmptyText("暂无数据")
                                  .BottomBar(X.PagingToolbar().DisplayInfo(true))
                      ),
                   X.Window()
                  .ID("WinAddFunction")
                  .Title("添加系统功能")
                  .Icon(Icon.TableEdit)
                  .Height(350)
                  .Width(600)
                  .Hidden(true)
                  .Modal(true)

                  .Loader(X.ComponentLoader().ID("AddFunctionLoader").Mode(LoadMode.Frame).LoadMask(lm =>
                  {
                      lm.ShowMask = true;
                      lm.Msg = "读取中...";
                  })),
              X.Window()
                  .ID("WinModFunction")
                      .Title("修改系统功能")
                  .Icon(Icon.TableEdit)
                  .Height(300)
                  .Width(600)
                  .Hidden(true)
                  .Modal(true)
                  .Loader(X.ComponentLoader().ID("ModFunctionLoader").Mode(LoadMode.Frame).LoadMask(lm =>
                  {
                      lm.ShowMask = true;
                      lm.Msg = "读取中...";
                  }))
          ))

<script type="text/javascript">

    function FunctionSearch() {
        App.FunctionGrid.setLoading(true);
        App.searchCondition.setValue(JSON.stringify(serializeJson("SearchFunction")));
        App.FunctionGrid.getStore().reload();
        App.FunctionGrid.setLoading(false);

        //App.direct.SearchOrder(
        //    serializeJson("SearchOrder"),
        //    {
        //        success: function(result) {
        //            App.OrderGrid.setLoading(false);
        //        },
        //        failure: function(error) {
        //            App.OrderGrid.setLoading(false);
        //        }
        //    });
    }


    function FilmSearchReset() {

    }

    function DelFunction() {
        var selectRow = Ext.getCmp("FunctionGrid").getSelectionModel().getSelection();
        if (selectRow.length == 0) {
            Ext.Msg.alert('信息', "请选择一条记录");
            return;
        }

        Ext.Msg.confirm("提示!", "您确定要删除该单吗?", function (btn) {
            if (btn != "yes") return;
            App.direct.DelFunction(
                selectRow[0].data.mid,
                {
                    success: function (result) {
                        if (result.Result != "OK") {
                            Ext.Msg.alert('信息', result.Message);
                        } else {
                            Ext.Msg.alert('信息', result.Message);
                            FilmSearch();
                        }
                    },
                    failure: function (error) {
                        Ext.Msg.alert('信息', result.Message);
                    }
                }
            );
        });
    }

    function ShowAddFunction() {
        App.WinAddFunction.show();
        App.WinAddFunction.loader.load({ //也可以这样写
            url: "../Sys/AddFunction",
            scripts: true,
            renderer: "frame"
        });

    }


    function ShowModFunction() {
        var selectRow = Ext.getCmp("FunctionGrid").getSelectionModel().getSelection();
        if (selectRow.length == 0) {
            Ext.Msg.alert('信息', "请选择一条记录");
            return;
        }
        App.WinModFunction.show();
        App.WinModFunction.loader.load({ //也可以这样写
            url: "../Sys/ModFunction?mid=" + selectRow[0].data.mid,
            scripts: true,
            renderer: "frame"

        });
    }


    function FilmShowDelOrder() {

    }
</script>